<?php  
class ControllerPacharaHome extends Controller {
	public function index() {
		$this->language->load('pachara/home');
		
		$this->document->title = $this->config->get('config_title');
		$this->document->description = $this->config->get('config_meta_description');
		
		$this->data['heading_title'] = sprintf($this->language->get('heading_title'), $this->config->get('config_name'));
		
		
		$this->data['categories'] = $this->getCat(0);
		// End Get Category List
								
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/pachara/home.tpl')) {
			$this->template = $this->config->get('config_template') . '/template/pachara/home.tpl';
		} else {
			$this->template = 'default/template/pachara/home.tpl';
		}
		
		$this->children = array();
		
		$this->load->model('checkout/extension');
		
		$module_data = $this->model_checkout_extension->getExtensionsByPosition('module', 'home');
		
		foreach ($module_data as $result) {
			$this->children[] = 'module/' . $result['code'];
		}
		
		$this->children[] = 'common/column_right';
		$this->children[] =	'common/column_left';
		$this->children[] =	'common/footer';
		$this->children[] =	'common/header';
		
		$this->response->setOutput($this->render(TRUE), $this->config->get('config_compression'));
	}

	protected function getCat($id){
		$this->load->model('catalog/category');
		$categories = "";
		$results= $this->model_catalog_category->getCategories($id);
		if ($results) { 
			$categories .= '<ul id="pachara-ul">';
    	}
		foreach ($results as $result) {	
			$categories .= '<li>';
        	$categories .= $result["name"];
        	if($result['category_id'] != null){
        		$children = $this->getCat($result['category_id']);
        		$categories .= $children;
        	}
        	$categories .= '</li>'; 
		}
		if ($results) {
			$categories .= '</ul>';
		}
		return $categories;
	}
}
?>